isLogin()
// 拿到存在localStorage 的id
const itemInfo = localStorage.getItem('item_info')
// console.log(itemInfo)

// 根据id去拿数据渲染
$.ajax({
    url: 'assets/js/food.json',
    type: 'GET',
    success: function(res) {
        res.forEach(item => {
            
            if(item.id == itemInfo) {
                $('#foodname').text(item.title),
                $('.price').text(`￥${item.price}`)
                $('.img-item').prop('src', item.img)
                return
            }
        })
    }
})

// 添加购物车
$('#joinCart').click(() => {
    $.ajax({
        url: '/foods/join',
        type: 'POST',
        data: {
            userId: localStorage.getItem('user_id'),
            foodId: itemInfo,
            foodNum: 1,
            username: localStorage.getItem('username')
        },
        success: function(res) {
			if (res.code === 0) {
				console.log(res)
				window.location.href = './cart.html'
			} else {
				alert('添加失败')
			}
		},
    })
})